﻿; (function ($) {
    $.extend({
       
        //加法
        "plus":function (arg1, arg2) {
            var r1, r2, m;
            try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
            try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
            m = Math.pow(10, Math.max(r1, r2))
            var s1 = Math.round(arg1 * m);
            var s2 = Math.round(arg2 * m);
            return (s1 + s2) / m
        },
        //减法
        "minus":function (arg1, arg2) {
            var r1, r2, m;
            try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
            try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
            m = Math.pow(10, Math.max(r1, r2))
            var s1 = Math.round(arg1 * m);
            var s2 = Math.round(arg2 * m);
            return (s1 - s2) / m
        },

        //乘法
          "multiply":function (arg1, arg2) {
            if (isNaN(arg1) || isNaN(arg2)) { return; }
            var r1, r2, m;
            try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
            try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
            m = Math.pow(10, Math.max(r1, r2))
            var s1 = Math.round(arg1 * m);
            var s2 = Math.round(arg2 * m);
            return (s1 * s2) / (m * m);
        },
         //除法
          "divide":function (arg1, arg2) {
            if (isNaN(arg1) || isNaN(arg2)) { return; }
            var r1, r2, m;
            try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
            try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
            m = Math.pow(10, Math.max(r1, r2))
            var s1 = Math.round(arg1 * m);
            var s2 = Math.round(arg2 * m);
            var result=  (s1 / s2);
            return Math.floor(result * Math.pow(10, m) + 0.5) / Math.pow(10, m);
        }
    });
 })(jQuery);
